﻿class SpringOffset extends MovieClip {
	var springLength:Number = 50;
	var spring:Number = .1;
	var friction:Number = .85;
	var container_mc:MovieClip;
	var b_head:Ball;
	var b_body1:Ball;
	var b_body2:Ball;
	var b_r_hand1:Ball;
	var b_r_hand2:Ball;
	var b_l_hand1:Ball;
	var b_l_hand2:Ball;
	var b_r_foot1:Ball;
	var b_r_foot2:Ball;
	var b_l_foot1:Ball;
	var b_l_foot2:Ball;
	function SpringOffset() {
		init();
	}
	function init():Void {
		container_mc = createEmptyMovieClip("container_mc", 2);
		container_mc._x = Stage.width/2;
		container_mc._y = Stage.height/2;
		var depth:Number = 100;
		b_head = new Ball(container_mc.createEmptyMovieClip("b"+depth, depth++), 10);
		b_body1 = new Ball(container_mc.createEmptyMovieClip("b"+depth, depth++), 10);
		b_body2 = new Ball(container_mc.createEmptyMovieClip("b"+depth, depth++), 10);
		b_r_hand1 = new Ball(container_mc.createEmptyMovieClip("b"+depth, depth++), 10);
		b_r_hand2 = new Ball(container_mc.createEmptyMovieClip("b"+depth, depth++), 10);
		b_l_hand1 = new Ball(container_mc.createEmptyMovieClip("b"+depth, depth++), 10);
		b_l_hand2 = new Ball(container_mc.createEmptyMovieClip("b"+depth, depth++), 10);
		b_r_foot1 = new Ball(container_mc.createEmptyMovieClip("b"+depth, depth++), 10);
		b_r_foot2 = new Ball(container_mc.createEmptyMovieClip("b"+depth, depth++), 10);
		b_l_foot1 = new Ball(container_mc.createEmptyMovieClip("b"+depth, depth++), 10);
		b_l_foot2 = new Ball(container_mc.createEmptyMovieClip("b"+depth, depth++), 10);
	}
	function onEnterFrame():Void {
		container_mc.clear();
		container_mc.lineStyle(0, 0x000000, 100);
		//頭 VS 胸
		b_head.springTo(b_body1, 0, -2, springLength, spring, friction);
		b_body1.springTo(b_head, 0, 2, springLength, spring, friction);
		container_mc.moveTo(b_head.x, b_head.y);
		container_mc.lineTo(b_body1.x, b_body1.y);
		//胸 VS 臀
		b_body1.springTo(b_body2, 0, -2, springLength, spring, friction);
		b_body2.springTo(b_body1, 0, 2, springLength, spring, friction);
		container_mc.moveTo(b_body1.x, b_body1.y);
		container_mc.lineTo(b_body2.x, b_body2.y);
		//胸 VS 左大臂
		b_body1.springTo(b_l_hand1, 2, -1, springLength, spring, friction);
		b_l_hand1.springTo(b_body1, -2, 1, springLength, spring, friction);
		container_mc.moveTo(b_body1.x, b_body1.y);
		container_mc.lineTo(b_l_hand1.x, b_l_hand1.y);
		//左大臂 VS 左前臂
		b_l_hand1.springTo(b_l_hand2, 0, -2, springLength, spring, friction);
		b_l_hand2.springTo(b_l_hand1, 0, 2, springLength, spring, friction);
		container_mc.moveTo(b_l_hand1.x, b_l_hand1.y);
		container_mc.lineTo(b_l_hand2.x, b_l_hand2.y);
		//胸 VS 右大臂
		b_body1.springTo(b_r_hand1, -2, -1, springLength, spring, friction);
		b_r_hand1.springTo(b_body1, 2, 1, springLength, spring, friction);
		container_mc.moveTo(b_body1.x, b_body1.y);
		container_mc.lineTo(b_r_hand1.x, b_r_hand1.y);
		//右大臂 VS 右前臂
		b_r_hand1.springTo(b_r_hand2, 0, -2, springLength, spring, friction);
		b_r_hand2.springTo(b_r_hand1, 0, 2, springLength, spring, friction);
		container_mc.moveTo(b_r_hand1.x, b_r_hand1.y);
		container_mc.lineTo(b_r_hand2.x, b_r_hand2.y);
		//臀 VS 左大腿
		b_body2.springTo(b_l_foot1, 1, -2, springLength, spring, friction);
		b_l_foot1.springTo(b_body2, -1, 2, springLength, spring, friction);
		container_mc.moveTo(b_body2.x, b_body2.y);
		container_mc.lineTo(b_l_foot1.x, b_l_foot1.y);
		//左大腿 VS 左小腿
		b_l_foot1.springTo(b_l_foot2, 0, -2, springLength, spring, friction);
		b_l_foot2.springTo(b_l_foot1, 0, 2, springLength, spring, friction);
		container_mc.moveTo(b_l_foot1.x, b_l_foot1.y);
		container_mc.lineTo(b_l_foot2.x, b_l_foot2.y);
		//臀 VS 右大腿
		b_body2.springTo(b_r_foot1, -1, -2, springLength, spring, friction);
		b_r_foot1.springTo(b_body2, 1, 2, springLength, spring, friction);
		container_mc.moveTo(b_body2.x, b_body2.y);
		container_mc.lineTo(b_r_foot1.x, b_r_foot1.y);
		//右大腿 VS 右小腿
		b_r_foot1.springTo(b_r_foot2, 0, -2, springLength, spring, friction);
		b_r_foot2.springTo(b_r_foot1, 0, 2, springLength, spring, friction);
		container_mc.moveTo(b_r_foot1.x, b_r_foot1.y);
		container_mc.lineTo(b_r_foot2.x, b_r_foot2.y);
	}
}
